import { createRouter, createWebHashHistory } from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import StayLanShouList from '../components/expressManage/StayLanShouList.vue'
import CanBePackaged from '../components/expressManage/CanBePackaged.vue'
import CanSend from '../components/expressManage/CanSend.vue'
import HistoryQuery from '../components/expressManage/HistoryQuery.vue'
import PackageList from '../components/packageManage/PackageList.vue'

const routes = [
    // 重定向至登录界面
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    {
        path: '/home',
        component: Home,
        redirect: '/welcome',
        children: [
            { path: '/welcome', component: Welcome },
            { path: '/stayLanShou', component: StayLanShouList },
            { path: '/canBepackaged', component: CanBePackaged },
            { path: '/canSend', component: CanSend },
            { path: '/historyQuery', component: HistoryQuery },
            { path: '/packageList', component: PackageList }
        ]
    }
]

const router = createRouter({
        history: createWebHashHistory(),
        routes
    })
    // 挂载路由导航守卫 用id
router.beforeEach((to, from, next) => {
    if (to.path === '/login') next()
        // 获取id
    const idStr = window.sessionStorage.getItem('id')
    if (!idStr) return next('/login')
    next()
})

export default router